#!/bin/sh

DAEMON="syslogd"
DAEMON_ARGS="-n -C64 -S -t -D $RSYSLOG_ADDRESS"

# -n              Run in foreground
# -R HOST[:PORT]  Log to HOST:PORT (default PORT:514)
# -L              Log locally and via network (default is network only if -R)
# -C[size_kb]     Log to shared mem buffer (use logread to read it)
# -O FILE         Log to FILE (default: /var/log/messages, stdout if -)
# -s SIZE         Max size (KB) before rotation (default 200KB, 0=off)
# -b N            N rotated logs to keep (default 1, max 99, 0=purge)
# -l N            Log only messages more urgent than prio N (1-8)
# -S              Smaller output
# -t              Strip client-generated timestamps
# -D              Drop duplicates

PIDFILE="/run/$DAEMON.pid"

. /usr/share/common

if [ -n "$rsyslog_host" ]; then
	echo_info "Adding remote logging to $rsyslog_host:${rsyslog_port:-514}"
	DAEMON_ARGS="$DAEMON_ARGS -R $rsyslog_host:${rsyslog_port:-514}"
fi

if [ "true" = "$rsyslog_local" ]; then
	echo_info "Adding local logging"
	DAEMON_ARGS="$DAEMON_ARGS -L"
fi

start() {
	echo_title "Starting syslogd"

	start_daemon
}

stop() {
	echo_title "Stopping syslogd"

	stop_daemon
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		stop
		sleep 1
		start
		;;
	*)
		echo "Usage: $0 {start|stop|restart}"
		exit 1
		;;
esac

exit 0
